package com.ruoyi.web.controller.drinkwater;


import com.ruoyi.base.domain.BusWaterSegment;
import com.ruoyi.base.domain.BussinessItemVo;
import com.ruoyi.base.service.IBusWaterSegmentService;
import com.ruoyi.base.service.PublicToolsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.monitor.service.IBusWaterAutomonitorDaydataService;
import com.ruoyi.monitor.service.IBusWaterAutomonitorevaluateDaydataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 饮用水源地水质日历接口
 */
@RestController
@RequestMapping("/drink/autoReport")
public class BusWaterDrinkAutoReportController extends BaseController {

    @Autowired
    private PublicToolsService publicToolsService;
    @Autowired
    private IBusWaterSegmentService busWaterSegmentService;
    @Autowired
    private IBusWaterAutomonitorevaluateDaydataService busWaterAutomonitorevaluateDaydataService;
    @Autowired
    private IBusWaterAutomonitorDaydataService busWaterAutomonitorDaydataService;

    /**
     * 监测项目
     * @return
     */
    @GetMapping("/itemList")
    public AjaxResult itemList()
    {
        BussinessItemVo vo = new BussinessItemVo();
        vo.setBussinessCategoryCode("DrinkAuto");
        List<Map<String,Object>> list=publicToolsService.bussinessItemData(vo);
        List<Map> resMapList = new ArrayList<>();
        Map map1 = new HashMap();
        map1.put("itemCode","1");
        map1.put("itemName","水质类型");
        resMapList.add(map1);

        if(!CollectionUtils.isEmpty(list)){
            for (Map<String, Object> stringObjectMap : list) {
                Map map = new HashMap();
                map.put("itemCode",stringObjectMap.get("itemCode"));
                map.put("itemName",stringObjectMap.get("itemName"));
                resMapList.add(map);
            }
        }
        return AjaxResult.success(resMapList);
    }

    /**
     * 监测断面
     * @return
     */
    @GetMapping("/segmentTree")
    public AjaxResult segmentList()
    {
        Map rootMap = new HashMap();
        rootMap.put("pId",null);
        rootMap.put("id",0);
        rootMap.put("name","全部类型");


        List<Map> resMapList = new ArrayList<>();
        BusWaterSegment param = new BusWaterSegment();
        param.setIsauto("1");
        param.setIsdrink("1");
        List<BusWaterSegment> list = busWaterSegmentService.selectBusWaterSegmentList(param);
        if(!CollectionUtils.isEmpty(list)){
            for (BusWaterSegment busWaterSegment : list) {
                Map map = new HashMap();
                map.put("segmentId",busWaterSegment.getId());
                map.put("segmentName",busWaterSegment.getSegmentname());
                resMapList.add(map);
            }
        }
        return AjaxResult.success(resMapList);
    }

    /**
     * 日历
     * @return
     */
    @GetMapping("/calendarList")
    public AjaxResult calendarList(String year,String segmentId,String itemCode,String isOverStandard)
    {
        if(StringUtils.isEmpty(year)){
            throw new ServiceException("请选择年份");
        }
        if(StringUtils.isEmpty(segmentId)){
            throw new ServiceException("请选择断面");
        }
        if(StringUtils.isEmpty(itemCode)){
            throw new ServiceException("请选择监测项目");
        }
        BusWaterSegment busWaterSegment = busWaterSegmentService.selectBusWaterSegmentByID(segmentId);
        Map resMap = new HashMap();
        if("1".equals(itemCode)){
            resMap = busWaterAutomonitorevaluateDaydataService.autoQualityCalendar(year,segmentId,isOverStandard);
        }else{
            resMap = busWaterAutomonitorDaydataService.autoQualityCalendar(year,segmentId,itemCode,isOverStandard);
        }
        resMap.put("targetlevelname",busWaterSegment.getTargetlevelname());
        return AjaxResult.success(resMap);
    }
}
